/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PrePersist;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author Stefan
 */
@Entity
public class EventComment extends AbstractEntity implements Serializable {

    @Column(name = "text",length=511)
    protected String text;
    @Column(name = "created")
    @Temporal(TemporalType.TIMESTAMP)
    protected Date created;

    
    @JoinColumn(name = "registered_user_id", referencedColumnName = "id")
    @ManyToOne(optional = false, fetch = FetchType.EAGER)
    protected RegisteredUser registeredUser;


    @JoinColumn(name = "event_id", referencedColumnName = "id")
    @ManyToOne(optional = false, fetch = FetchType.EAGER)
    protected Event event;

    public EventComment() {
    }

    @PrePersist
    protected void onCreate() {
        created = Calendar.getInstance().getTime();
    }

    public EventComment(Event event, RegisteredUser user, String comment) {
        this.event = event;
        this.registeredUser = user;
        this.text = comment;
    }

    public Date getCreated() {
        return created;
    }

    public void setCreated(Date created) {
        this.created = created;
    }

    public Event getEvent() {
        return event;
    }

    public void setEvent(Event event) {
        this.event = event;
    }

    public RegisteredUser getRegisteredUser() {
        return registeredUser;
    }

    public void setRegisteredUser(RegisteredUser registeredUser) {
        this.registeredUser = registeredUser;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }
}
